<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- customwidget.qdoc -->
  <title>QDesignerCustomWidgetCollectionInterface 类 | Qt设计师手册</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtdesigner-manual.html">Qt设计师手册</a></td><td ><a href="qtdesigner-module.html">C++ 类</a></td><td >QDesignerCustomWidgetCollectionInterface</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtdesigner-manual.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QDesignerCustomWidgetCollectionInterface 类</h1>
<!-- $$$QDesignerCustomWidgetCollectionInterface-brief -->
<p><font style="vertical-align: inherit;">该</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetcollectioninterface.html"><font style="vertical-align: inherit;">QDesignerCustomWidgetCollectionInterface</font></a><font style="vertical-align: inherit;">类可以包含在一个单一的库中的多个自定义部件。</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetcollectioninterface.html#details"><font style="vertical-align: inherit;">更多...</font></a></p>
<!-- @@@QDesignerCustomWidgetCollectionInterface -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign">头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QDesignerCustomWidgetCollectionInterface&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += designer</td></tr></table></div><ul>
<li><a href="qdesignercustomwidgetcollectioninterface-members.html">所有成员的列表，包括继承成员。</a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qdesignercustomwidgetcollectioninterface.html#dtor.QDesignerCustomWidgetCollectionInterface">~QDesignerCustomWidgetCollectionInterface</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QList&lt;QDesignerCustomWidgetInterface *&gt; </td><td class="memItemRight bottomAlign"><b><a href="qdesignercustomwidgetcollectioninterface.html#customWidgets">customWidgets</a></b>() const = 0</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QDesignerCustomWidgetCollectionInterface-description -->
<div class="descr">
<h2 id="details">详细信息</h2>
<p><font style="vertical-align: inherit;">该</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetcollectioninterface.html"><font style="vertical-align: inherit;">QDesignerCustomWidgetCollectionInterface</font></a><font style="vertical-align: inherit;">类可以包含在一个单一的库中的多个自定义部件。</font></p>
<p><font style="vertical-align: inherit;">实现自定义组件插件时，您将其构建为单独的库。如果要在同一个库中包含多个自定义组件插件，则必须另外子类</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetcollectioninterface.html"><font style="vertical-align: inherit;">QDesignerCustomWidgetCollectionInterface</font></a><font style="vertical-align: inherit;">。</font></p>
<p><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetcollectioninterface.html"><font style="vertical-align: inherit;">QDesignerCustomWidgetCollectionInterface</font></a><font style="vertical-align: inherit;">包含一个返回集合的</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetinterface.html"><font style="vertical-align: inherit;">QDesignerCustomWidgetInterface</font></a><font style="vertical-align: inherit;">对象列表的函数。例如，如果您有多个自定义组件</font><code>CustomWidgetOne</code><font style="vertical-align: inherit;">,</font><code>CustomWidgetTwo</code><font style="vertical-align: inherit;">和</font><code>CustomWidgetThree</code><font style="vertical-align: inherit;">，则类定义可能如下所示：</font></p>
<pre class="cpp">

  <span class="preprocessor">#include customwidgetoneinterface.h</span>
  <span class="preprocessor">#include customwidgettwointerface.h</span>
  <span class="preprocessor">#include customwidgetthreeinterface.h</span>

  <span class="preprocessor">#include &lt;Qt设计师/qtdesigner.h&gt;</span>
  <span class="preprocessor">#include &lt;QtCore/qplugin.h&gt;</span>

  <span class="keyword">class</span> MyCustomWidgets: <span class="keyword">public</span> <span class="type"><a href="../qtcore/qobject.html">QObject</a></span><span class="operator">,</span> <span class="keyword">public</span> <span class="type"><a href="qdesignercustomwidgetcollectioninterface.html">QDesignerCustomWidgetCollectionInterface</a></span>
  {
      Q_OBJECT
      Q_PLUGIN_METADATA(IID <span class="string">&quot;org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface&quot;</span>)
      Q_INTERFACES(<span class="type"><a href="qdesignercustomwidgetcollectioninterface.html">QDesignerCustomWidgetCollectionInterface</a></span>)

  <span class="keyword">public</span>:
      MyCustomWidgets(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);

      <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a></span><span class="operator">*</span><span class="operator">&gt;</span> customWidgets() <span class="keyword">const</span> override;

  <span class="keyword">private</span>:
      <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a></span><span class="operator">*</span><span class="operator">&gt;</span> widgets;
  };

</pre>
<p><font style="vertical-align: inherit;">在类构造函数中，您将自定义组件的接口添加到您在</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetcollectioninterface.html#customWidgets"><font style="vertical-align: inherit;">customWidgets</font></a><font style="vertical-align: inherit;"> () 函数中返回的列表中：</font></p>
<pre class="cpp">

  MyCustomWidgets<span class="operator">::</span>MyCustomWidgets(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> <span class="operator">*</span>parent)
          : <span class="type"><a href="../qtcore/qobject.html">QObject</a></span>(parent)
  {
      widgets<span class="operator">.</span>append(<span class="keyword">new</span> CustomWidgetOneInterface(<span class="keyword">this</span>));
      widgets<span class="operator">.</span>append(<span class="keyword">new</span> CustomWidgetTwoInterface(<span class="keyword">this</span>));
      widgets<span class="operator">.</span>append(<span class="keyword">new</span> CustomWidgetThreeInterface(<span class="keyword">this</span>));
  }

  <span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a></span><span class="operator">*</span><span class="operator">&gt;</span> MyCustomWidgets<span class="operator">::</span>customWidgets() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> widgets;
  }

</pre>
<p><font style="vertical-align: inherit;">请注意，不是使用</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qtplugin.html#Q_PLUGIN_METADATA"><font style="vertical-align: inherit;">Q_PLUGIN_METADATA</font></a><font style="vertical-align: inherit;"> () 宏导出每个自定义组件插件，而是导出整个集合。所述</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qtplugin.html#Q_PLUGIN_METADATA"><font style="vertical-align: inherit;">Q_PLUGIN_METADATA</font></a><font style="vertical-align: inherit;">（）宏确保</font><i><font style="vertical-align: inherit;">Qt设计</font></i><font style="vertical-align: inherit;">可以访问并构建定制的窗口组件。没有这个宏，</font><i><font style="vertical-align: inherit;">Qt 设计师 就</font></i><font style="vertical-align: inherit;">无法使用它们。</font></p>
</div>
<p><b><font style="vertical-align: inherit;">请参考</font></b><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/qdesignercustomwidgetinterface.html"><font style="vertical-align: inherit;">QDesignerCustomWidgetInterface</font></a><font style="vertical-align: inherit;">和</font><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdesigner/designer-creating-custom-widgets.html"><font style="vertical-align: inherit;">为 Qt 设计师 创建自定义组件</font></a><font style="vertical-align: inherit;">。</font></p>
<!-- @@@QDesignerCustomWidgetCollectionInterface -->
<div class="func">
<h2>成员函数文档</h2>
<!-- $$$~QDesignerCustomWidgetCollectionInterface[overload1]$$$~QDesignerCustomWidgetCollectionInterface -->
<h3 class="fn" id="dtor.QDesignerCustomWidgetCollectionInterface"><a name="dtor.QDesignerCustomWidgetCollectionInterface"></a><code>[virtual] </code>QDesignerCustomWidgetCollectionInterface::<span class="name">~QDesignerCustomWidgetCollectionInterface</span>()</h3>
<p><font style="vertical-align: inherit;">销毁自定义组件集合界面。</font></p>
<!-- @@@~QDesignerCustomWidgetCollectionInterface -->
<!-- $$$customWidgets[overload1]$$$customWidgets -->
<h3 class="fn" id="customWidgets"><a name="customWidgets"></a><code>[pure virtual] </code><span class="type"><a href="../qtcore/qlist.html">QList</a></span>&lt;<span class="type"><a href="qdesignercustomwidgetinterface.html">QDesignerCustomWidgetInterface</a></span> *&gt; QDesignerCustomWidgetCollectionInterface::<span class="name">customWidgets</span>() const</h3>
<p><font style="vertical-align: inherit;">返回集合的自定义组件的接口列表。</font></p>
<!-- @@@customWidgets -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
